<?php
	// views/products/edit.ctp
?>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script>
	var i=0;
	function addRow(div)
	{
		i++;
		var iPro = document.createElement('input');
		iPro.type = 'text';
		iPro.name='properties[' + i + ']';
		
	    var iVal = document.createElement('input');
	    iVal.type = 'text';
	    iVal.name='value[' + i + ']';
	    
		div.appendChild(iPro);
		div.appendChild(iVal);
	}
	function bup()
	{
		var properties = $("input[name^='properties']");
		var values = $("input[name^='value']");
		var tmp= "";
		for (var l=0; l < properties.length; l++)
		{
			tmp += properties[l].value + ":" + values[l].value + "/";
		}
		document.getElementById('ProductDescription').value = tmp;
		document.getElementById('ProductEditForm').submit();
	}
	
</script>


<?php echo $form->create('Product',array('type'=>'file',  'action' => 'edit'));?>

 	<h2><?php __('Sửa thông tin sản phẩm');?></h2>
 	<?php $session->flash();?>
 	<div class="group">
		<div class="lf"><?php __('Loại sản phẩm');?></div>
		<div class="rf"><?php echo $form->input('category_id',array('label'=>'', array('options'=>$categories))); ?></div>
	</div>
	<div class="group">
		<div class="lf"><?php __('Hãng sản xuất');?></div>
		<div class="rf"><?php echo $form->input('brand_id',array('label'=>'', array('options'=>$brands))); ?></div>
	</div>
	<div class="group">
		<div class="lf"><?php __('Tên Sản Phẩm');?></div>
		<div class="rf"><?php echo $form->input('name', array('label' => '', 'size'=>'50')); ?></div>
	</div>
	<div class="group">
		<div class="lf"><?php __('Mô tả');?></div>
		<div class="rf">
		<?php 
		echo $form->hidden('description');
			/*
			echo $tinymce->input('description', array('label' => '','cols'=>'88','rows'=>'20', 'error' => false), array(
							            'theme' => 'advanced',
							            'plugins' => "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
								        'theme_advanced_buttons1' => "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
										'theme_advanced_buttons2'  =>  "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
										'theme_advanced_buttons3'  =>  "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
										'theme_advanced_toolbar_location'  =>  "top",
										'theme_advanced_toolbar_align'  =>  "left",
										'theme_advanced_statusbar_location'  =>  "bottom",
						          		'file_browser_callback' => 'fileBrowserCallBack',
										'theme_advanced_resizing'  => true
							        ));
							        */
		?>
		<div id="content" style="width:300px; float:left;">
			
		</div>
		<div style="width:300px; float:left;">
			<a onclick="addRow(document.getElementById('content'))">add</a>	
		</div>
		<div style="clear:both;"></div>
		
		<script>
			var strDes = "<?php echo $this->data["Product"]["description"];?>";
			var arrDes = strDes.split("/");
			for(var l=0; l< arrDes.length; l++)
			{
				if(arrDes[l].length > 0)
				{
					var iPro = document.createElement('input');
					iPro.type = 'text';
					iPro.name = 'properties[' + i + ']';
					iPro.value = arrDes[l].split(":")[0];
				    var iVal = document.createElement('input');
				    iVal.type = 'text';
				    iVal.name='value[' + i + ']';
				    iVal.value = arrDes[l].split(":")[1];
				    
				    document.getElementById('content').appendChild(iPro);
				    document.getElementById('content').appendChild(iVal);
					i++;
				}
			}
		</script>
		
		
		
		</div>
	</div>
	<div class="group">
		<div class="lf"><?php __('Giá Sản Phẩm');?></div>
		<div class="rf"><?php echo $form->input('price', array('label' => '', 'size'=>'10', 'maxlength'=>'20')); ?></div>
	</div>
	<div class="group">
		<div class="lf"><?php __('Số lượng trong kho');?></div>
		<div class="rf"><?php echo $form->input('quantity', array('label' => '', 'size'=>'30')); ?></div>
	</div>
	<div class="group">
		<div class="lf"><?php __('Sản Phẩm HOT');?></div>
		<div class="rf"><?php echo $form->input('is_hot', array('label' => '', 'size'=>'10')); ?></div>
	</div>
	<div class="group">
		<div class="lf"><?php __('Sản Phẩm Mới');?></div>
		<div class="rf"><?php echo $form->input('is_new', array('label' => '', 'size'=>'10')); ?></div>
	</div>
	<div class="group">
			<div class="lf"><?php __('Ảnh đại diện');?></div>
			<div class="rf"><?php echo $form->file('imagess',array('label'=>'',)); ?></div>
	</div>
	
	<br />
	<?php echo $form->input('id', array('type'=>'hidden'));?>
	<input name="action" value="edit" type="hidden">
	<input type="button" name="xxx" onclick="bup()" value=" Lưu lại " />
	<br />
<?php echo $form->end();?>